package org.emet.entity.storage;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.emet.jee.console.entity.BaseEntity;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;

/**
 * 销售物品项
 * 
 * @author alex
 * 
 */
@Entity
@Table(name = "T_SALE_ITEM")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SaleItem extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Date date = new Date();
	private Item item;
	/** 进货/销售单价 */
	private BigDecimal singlePrice = new BigDecimal(0.00);
	/** 进货/销售数量 */
	private int itemCount = 0;
	/** 进货/销售金额合计 */
	private BigDecimal amount = new BigDecimal(0.00);
	private SaleHist saleHist;

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public BigDecimal getSinglePrice() {
		return singlePrice;
	}

	@ManyToOne
	@JoinColumn(name = "item_id")
	public Item getItem() {
		return item;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	public void setSinglePrice(BigDecimal singlePrice) {
		this.singlePrice = singlePrice;
	}

	public int getItemCount() {
		return itemCount;
	}

	public void setItemCount(int itemCount) {
		this.itemCount = itemCount;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	@ManyToOne(targetEntity = SaleHist.class)
	@Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE })
	@JoinColumn(name = "sale_hist_id")
	public SaleHist getSaleHist() {
		return saleHist;
	}

	public void setSaleHist(SaleHist saleHist) {
		this.saleHist = saleHist;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
